<%
Class FastAsp_Request
    Private m_Get     'GET参数字典
    Private m_Post    'POST参数字典
    Private m_Filter  '是否开启过滤
    
    Private Sub Class_Initialize()
        Set m_Get = Server.CreateObject("Scripting.Dictionary")
        Set m_Post = Server.CreateObject("Scripting.Dictionary")
        m_Filter = GetConfig("XssFilter")
        
        '初始化参数
        InitParams()
    End Sub
    
    '初始化参数
    Private Sub InitParams()
        Dim item
        
        '处理GET参数
        For Each item In Request.QueryString
            If Request.QueryString(item).Count > 1 Then
                m_Get.Add item, Request.QueryString(item)
            Else
                m_Get.Add item, Request.QueryString(item)
            End If
        Next
        
        '处理POST参数
        For Each item In Request.Form
            If Request.Form(item).Count > 1 Then
                m_Post.Add item, Request.Form(item)
            Else
                m_Post.Add item, Request.Form(item)
            End If
        Next
    End Sub
    
    '获取GET参数
    Public Function [Get](byval name)
        If name = "" Then
            Set [Get] = m_Get
        ElseIf m_Get.Exists(name) Then
            [Get] = FilterValue(m_Get(name))
        Else
            [Get] = ""
        End If
    End Function
    
    '获取POST参数
    Public Function Post(byval name)
        If name = "" Then
            Set Post = m_Post
        ElseIf m_Post.Exists(name) Then
            Post = FilterValue(m_Post(name))
        Else
            Post = ""
        End If
    End Function
    
    '获取所有参数(GET+POST)
    Public Function Param(byval name)
        If name = "" Then
            Set Param = Server.CreateObject("Scripting.Dictionary")
            Dim key
            For Each key In m_Get.Keys
                Param.Add key, m_Get(key)
            Next
            For Each key In m_Post.Keys
                If Not Param.Exists(key) Then
                    Param.Add key, m_Post(key)
                End If
            Next
        ElseIf m_Post.Exists(name) Then
            Param = FilterValue(m_Post(name))
        ElseIf m_Get.Exists(name) Then
            Param = FilterValue(m_Get(name))
        Else
            Param = ""
        End If
    End Function
    
    '获取请求方法
    Public Function Method()
        Method = Request.ServerVariables("REQUEST_METHOD")
    End Function
    
    '过滤参数值
    Private Function FilterValue(byval value)
        If Not m_Filter Then
            FilterValue = value
            Exit Function
        End If
        
        If IsArray(value) Then
            Dim i, arr()
            ReDim arr(UBound(value))
            For i = 0 To UBound(value)
                arr(i) = FilterXSS(value(i))
            Next
            FilterValue = arr
        Else
            FilterValue = FilterXSS(value)
        End If
    End Function
    
    '设置是否开启过滤
    Public Property Let Filter(byval value)
        m_Filter = value
    End Property
    
    Private Sub Class_Terminate()
        Set m_Get = Nothing
        Set m_Post = Nothing
    End Sub
End Class
%> 